<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增终端库')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-library-addPos" enctype="multipart/form-data">
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">品牌名称：</label>
                <div class="col-sm-8">
                    <input name="manuName" onclick="selectModel()" readonly id="manuName" type="text" class="form-control" required>
                    <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
                </div>
            </div>
            <input name="id" id="id" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">终端型号：</label>
                <div class="col-sm-8">
                    <input name="model"  readonly id="model" type="text" class="form-control" required>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">流量费：</label>
                <div class="col-sm-8">
                    <select name="sim_fee" class="form-control m-b" th:with="type=${@dict.getType('sim_fee')}">
                        <option value="0">0</option>
                    </select>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">服务费：</label>
                <div class="col-sm-8">
                    <select name="service_fee" class="form-control m-b" th:with="type=${@dict.getType('service_fee')}">
                        <option value="0">0</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">终端来源：</label>
                <div class="col-sm-8">
                    <select name="source" class="form-control m-b">
                        <option value="0">定制机</option>
                        <option value="1">自备机</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">终端文件：</label>
                <div class="col-sm-8">
                    <span class="btn btn-white btn-file">
                        <input type="file" name="file"  accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
                    </span>
                </div>
            </div>
            <div class="form-group" id="pos_network">
                <label class="col-sm-3 control-label is-required">网络类型：</label>
                <div class="col-sm-8">
                    <select name="posNetwork" class="form-control m-b">
                        <option value="">请选择</option>
                        <option value="4">4G</option>
                        <option value="2">2G</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">机器版本：</label>
                <div class="col-sm-8">
                    <select name="pos_version" class="form-control m-b">
                        <option value="">请选择</option>
                        <option value="1">1.0</option>
                        <option value="2">2.0</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">

        /**
         * 只有B版才可选择终端网络类型
         */
        function typeOnachage(obj) {
            if (obj.value == 'A'){
                $("#pos_network").hide();
            } else {
                $("#pos_network").show();
            }
        }


        var prefix = ctx + "terminal/library"
        $("#form-library-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var formData = new FormData();
                formData.append("file", $("[name = 'file']")[0].files[0]);
                formData.append("manuName",$("[name='manuName']").val());
                formData.append("term_num",$("[name='id']").val());
                formData.append("source",$("[name='source']").val());
                formData.append("posNetwork",$("[name='posNetwork']").val());
                formData.append("sim_fee",$("[name='sim_fee']").val());
                formData.append("service_fee",$("[name='service_fee']").val());
                formData.append("pos_version",$("[name='pos_version']").val());

                // $.operate.save(, formData);
                $.ajax({
                    url: prefix + "/savePos",
                    data: formData,
                    type: "post",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                        $.operate.saveSuccess(result);
                    }
                })
            }
        }
        function selectModel() {
            var url = ctx + "terminal/model/selectModel/";
            $.modal.open("选择型号" , url, '700');
        }
    </script>
</body>
</html>